package com.ymatou.iapi.godfreight.testcase;

import java.util.Arrays;
import java.util.List;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.ymatou.iapi.godfreight.parameter.queryCollectionGoodsAddressBean;
import com.ymatou.iapi.godfreight.service.queryCollectionGoodsAddressCall;
import com.ymatou.iapi.godfreightmgr.parameter.CreateCollectionGoodsAddressBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godfreight.CollectiongoodsAddress;
import com.ymttest.database.sqlwapper.godfreight.CollectionGoodsWapper;
import com.ymttest.utils.TestDataManager;
/**
*商户自提点列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_queryCollectionGoodsAddress{
	private static queryCollectionGoodsAddressBean bean;
	private static queryCollectionGoodsAddressCall call;
	private CollectionGoodsWapper CollectionGoodsWapper=new CollectionGoodsWapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商户自提点列表");
	}

	@Before
	public void caseUp() {
		bean=new queryCollectionGoodsAddressBean();
		call=new queryCollectionGoodsAddressCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void check_verify() throws JSONException
	{
		Logger.verifyEquals("true", call.getSuccess(), "验证返回Success成功");
		List<CollectiongoodsAddress> return_list=CollectionGoodsWapper.selectCollectiongoodsAddress(null, bean.getSellerId());
		JsonArray jsonArray=call.getAddressList();
		Logger.verifyEquals(jsonArray.size(), return_list.size(), "验证返回的与数据库条数一致");
		for(int i=0;i<return_list.size();i++)
		{
			CollectiongoodsAddress db_address=return_list.get(i);
			JsonObject exp_obj=jsonArray.get(i).getAsJsonObject();
			Logger.comment("addressId:"+exp_obj.get("addressId").getAsInt());
			Logger.verifyEquals(exp_obj.get("addressId").getAsInt(), db_address.getAddressId(), "验证返回的addressId与数据库addressId中的字段addressId一致");
			Logger.verifyEquals(exp_obj.get("addressName").getAsString(), db_address.getAddressName(), "验证返回的AddressName与数据库collectiongoods_address中的字段AddressName一致");
			Logger.verifyEquals(exp_obj.get("addressType").getAsInt(), db_address.getAddressType(), "验证返回的AddressName与数据库AddressType中的字段AddressType一致");
			Logger.verifyEquals(exp_obj.get("baseAddress").getAsString(), db_address.getBaseAddress(), "验证返回的AddressName与数据库baseAddress中的字段baseAddress一致");
			Logger.verifyEquals(exp_obj.get("detailAddress").getAsString(), db_address.getDetailAddress(), "验证返回的AddressName与数据库DetailAddress中的字段DetailAddress一致");
			Logger.verifyEquals(exp_obj.get("phone").getAsString(), db_address.getAreaCode()+"-"+db_address.getMobile(), "验证返回的AddressName与数据库phone中的字段Mobile一致");
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddress_001() {
		Logger.start(true,"商户自提点列表-商家1条自提点");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            
            bean.setSellerIds(mchId_channl);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddress_002() {
		Logger.start(true,"商户自提点列表-商家2条自提点");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId1 = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            Thread.sleep(1000);
            createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId2 = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            
            bean.setSellerIds(mchId_channl);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddress_004() {
		Logger.start(true,"商户自提点列表-商家1未配置递配,配置自提");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddress_005() {
		Logger.start(true,"商户自提点列表-商家1未配置递配,配置自提,商家2未配置递配,配置自提");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddress_006() {
		Logger.start(true,"商户自提点列表-商家1配置递配,未配置自提,商家2配置递配未,配置自提");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddress_007() {
		Logger.start(true,"商户自提点列表-商家1配置递配,未配置自提,商家2未配置递配,配置自提");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddress_008() {
		Logger.start(true,"商户自提点列表-商户没有配置默认快递配送:true上门自提:false");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddress_009() {
		Logger.start(true,"商户自提点列表-商家编号列表为空");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}